/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 08 - 19
 * Time: 11:47
 */
//力扣142环形链表II
public class Solution2 {
    public ListNode detectCycle(ListNode head) {
        if(head == null) {
            return null;
        }
        ListNode fast = head;
        ListNode show = head;
        while((fast != null) && (fast.next != null)) {
            fast = fast.next.next;
            show = show.next;
            if(fast == show) {
                fast = head;
                while(fast!= show) {
                    fast = fast.next;
                    show = show.next;
                }
                return fast;
            }
        }
        return null;
    }
}